home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Mixed Mode Maddness / Emulator / Header / 6502.h next >
Text File  |  2000-06-23  |  8KB  |  326 lines

  1. // Addressing Modes
  2. enum {
  3.     None        = 0x00,
  4.     Relative    = 0x02,
  5.     IndX         = 0x01,
  6.     ZeroPage    = 0x05,
  7.     Immediate    = 0x09,
  8.     Accumulator = 0x09,
  9.     Absolute    = 0x0D,
  10.     IndY        = 0x11,
  11.     ZeroPageX    = 0x15,
  12.     AbsoluteY    = 0x19,
  13.     AbsoluteX    = 0x1D,
  14.     ZeroPageY    = 0x20,
  15.     Indirect    = 0x2D
  16. };
  17.  
  18. // BASE opcodes
  19. enum  {
  20.     ADC = 0x60,
  21.     AND = 0x20,
  22.     ASL = 0x01,
  23. /*
  24.     BCC = 0x90,
  25.     BCS    = 0xB0,
  26.     BEQ = 0xF0,
  27.     BNE = 0xD0,
  28.     BMI = 0x30,
  29.     BPL = 0x10,
  30.     BVC = 0x50,
  31.     BVS = 0x70,
  32. */
  33.  
  34.     BCC = 0x8E,
  35.     BCS    = 0xAE,
  36.     BEQ = 0xEE,
  37.     BNE = 0xCE,
  38.     BMI = 0x2E,
  39.     BPL = 0x0E,
  40.     BVC = 0x4E,
  41.     BVS = 0x6E,
  42.  
  43.     BIT = 0x1F,
  44.     BRK = 0x00,        
  45.     CLC = 0x18,
  46.     CLD = 0xD8,
  47.     CLI = 0x58,
  48.     CLV = 0xB8,
  49.     CMP = 0xC0,
  50.     CPX = 0xD7,
  51.     CPY = 0xB7,
  52.     DEC = 0xC1,
  53.     DEX = 0xCA,
  54.     DEY = 0x88,
  55.     EOR = 0x40,
  56.     INC = 0xE1,
  57.     INX = 0xE8,
  58.     INY = 0xC8,
  59.     JMP = 0x3F,
  60.     JSR = 0x13,
  61.     LDA = 0xA0,
  62.     LDX = 0xA1,        // Exception
  63.     LDY = 0x9F,        // Exception
  64.     LSR = 0x41,
  65.     NOP = 0xEA,
  66.     ORA    = 0x00,
  67.     PHA    = 0x48,
  68.     PHP    = 0x08,
  69.     PLA    = 0x68,
  70.     PLP = 0x28,
  71.     ROL = 0x21,
  72.     ROR = 0x61,
  73.     RTI = 0x40,
  74.     RTS = 0x60,
  75.     SBC = 0xE0,
  76.     SEC = 0x38,
  77.     SED = 0xF8,
  78.     SEI = 0x78,
  79.     STA = 0x80,
  80.     STX = 0x81,
  81.     STY = 0x79,
  82.     TAX = 0xAA,
  83.     TAY = 0xA8,
  84.     TSX = 0xBA,
  85.     TXA = 0x8A,
  86.     TXS = 0x9A,
  87.     TYA = 0x98
  88. };
  89.  
  90. // Processor Bits
  91. enum {
  92.     CBit = 1 << 0,
  93.     ZBit = 1 << 1,
  94.     IBit = 1 << 2,
  95.     DBit = 1 << 3,
  96.     BBit = 1 << 4,
  97.     VBit = 1 << 6,
  98.     NBit = 1 << 7
  99. };
  100.  
  101. // Exceptions to the addressing mode values
  102. enum {
  103.     _LDX_Immediate = 0xA2,
  104.     _LDY_Immediate = 0xA0
  105. };
  106.  
  107. #define ZEROBYTE_OP_FUNCTION_PROTO(op)    extern void _##op(void)
  108. #define ONEBYTE_OP_FUNCTION_PROTO(op)    extern void _##op(UInt8)
  109. #define TWOBYTE_OP_FUNCTION_PROTO(op)    extern void _##op(UInt8*)
  110. #define TWOBYTE_OP_FUNCTION_PROTOPC(op)    extern void _##op(UInt16)
  111.  
  112. ONEBYTE_OP_FUNCTION_PROTO(ADC);                // ADC
  113. ONEBYTE_OP_FUNCTION_PROTO(AND);                // AND
  114. TWOBYTE_OP_FUNCTION_PROTO(ASL);                // ASL
  115. ONEBYTE_OP_FUNCTION_PROTO(BCC);                // BCC
  116. ONEBYTE_OP_FUNCTION_PROTO(BCS);                // BCS
  117. ONEBYTE_OP_FUNCTION_PROTO(BEQ);                // BEQ
  118. ONEBYTE_OP_FUNCTION_PROTO(BNE);                // BNE
  119. ONEBYTE_OP_FUNCTION_PROTO(BMI);                // BMI
  120. ONEBYTE_OP_FUNCTION_PROTO(BPL);                // BPL
  121. ONEBYTE_OP_FUNCTION_PROTO(BVC);                // BVC
  122. ONEBYTE_OP_FUNCTION_PROTO(BVS);                // BVS
  123. TWOBYTE_OP_FUNCTION_PROTO(BIT);                // BIT
  124. ZEROBYTE_OP_FUNCTION_PROTO(BRK);            // BRK
  125. ZEROBYTE_OP_FUNCTION_PROTO(CLC);            // CLC
  126. ZEROBYTE_OP_FUNCTION_PROTO(CLD);            // CLD
  127. ZEROBYTE_OP_FUNCTION_PROTO(CLI);            // CLI
  128. ZEROBYTE_OP_FUNCTION_PROTO(CLV);            // CLV
  129. ONEBYTE_OP_FUNCTION_PROTO(CMP);                // CMP
  130. ONEBYTE_OP_FUNCTION_PROTO(CPX);                // CPX
  131. ONEBYTE_OP_FUNCTION_PROTO(CPY);                // CPY
  132. TWOBYTE_OP_FUNCTION_PROTO(DEC);                // DEC
  133. ZEROBYTE_OP_FUNCTION_PROTO(DEX);            // DEX
  134. ZEROBYTE_OP_FUNCTION_PROTO(DEY);            // DEY
  135. ONEBYTE_OP_FUNCTION_PROTO(EOR);                // EOR
  136. TWOBYTE_OP_FUNCTION_PROTO(INC);                // INC
  137. ZEROBYTE_OP_FUNCTION_PROTO(INX);            // INX
  138. ZEROBYTE_OP_FUNCTION_PROTO(INY);            // INY
  139. TWOBYTE_OP_FUNCTION_PROTOPC(JMP);            // JMP
  140. TWOBYTE_OP_FUNCTION_PROTOPC(JSR);            // JSR
  141. ONEBYTE_OP_FUNCTION_PROTO(LDA);                // LDA
  142. ONEBYTE_OP_FUNCTION_PROTO(LDX);                // LDX
  143. ONEBYTE_OP_FUNCTION_PROTO(LDY);                // LDY
  144. TWOBYTE_OP_FUNCTION_PROTO(LSR);                // LSR
  145. ZEROBYTE_OP_FUNCTION_PROTO(NOP);            // NOP
  146. ONEBYTE_OP_FUNCTION_PROTO(ORA);                // ORA
  147. ZEROBYTE_OP_FUNCTION_PROTO(PHA);            // PHA
  148. ZEROBYTE_OP_FUNCTION_PROTO(PHP);            // PHP
  149. ZEROBYTE_OP_FUNCTION_PROTO(PLA);            // PLA
  150. ZEROBYTE_OP_FUNCTION_PROTO(PLP);            // PLP
  151. TWOBYTE_OP_FUNCTION_PROTO(ROL);                // ROL
  152. TWOBYTE_OP_FUNCTION_PROTO(ROR);                // ROR
  153. ZEROBYTE_OP_FUNCTION_PROTO(RTI);            // RTI
  154. ZEROBYTE_OP_FUNCTION_PROTO(RTS);            // RTS
  155. ONEBYTE_OP_FUNCTION_PROTO(SBC);                // SBC
  156. ZEROBYTE_OP_FUNCTION_PROTO(SEC);            // SEC
  157. ZEROBYTE_OP_FUNCTION_PROTO(SED);            // SED
  158. ZEROBYTE_OP_FUNCTION_PROTO(SEI);            // SEI
  159. TWOBYTE_OP_FUNCTION_PROTO(STA);                // STA
  160. TWOBYTE_OP_FUNCTION_PROTO(STX);                // STX
  161. TWOBYTE_OP_FUNCTION_PROTO(STY);                // STY
  162. ZEROBYTE_OP_FUNCTION_PROTO(TAX);            // TAX
  163. ZEROBYTE_OP_FUNCTION_PROTO(TAY);            // TAY
  164. ZEROBYTE_OP_FUNCTION_PROTO(TSX);            // TSX
  165. ZEROBYTE_OP_FUNCTION_PROTO(TXA);            // TXA
  166. ZEROBYTE_OP_FUNCTION_PROTO(TXS);            // TXS
  167. ZEROBYTE_OP_FUNCTION_PROTO(TYA);            // TYA
  168.  
  169. #define OPCODEMODE(op, mode)                            op##_##mode = ##op+##mode
  170. #define OPCODEMODEEXCEPTION(op, mode, val)                op##_##mode = ##val
  171.  
  172. // Create enums for command values
  173. enum {
  174.     OPCODEMODE(ADC, Immediate),
  175.     OPCODEMODE(ADC, Absolute),
  176.     OPCODEMODE(ADC, ZeroPage),
  177.     OPCODEMODE(ADC, IndX),
  178.     OPCODEMODE(ADC, IndY),
  179.     OPCODEMODE(ADC, ZeroPageX),
  180.     OPCODEMODE(ADC, AbsoluteX),
  181.     OPCODEMODE(ADC, AbsoluteY),
  182.     OPCODEMODE(AND, Immediate),
  183.     OPCODEMODE(AND, Absolute),
  184.     OPCODEMODE(AND, ZeroPage),
  185.     OPCODEMODE(AND, IndX),
  186.     OPCODEMODE(AND, IndY),
  187.     OPCODEMODE(AND, ZeroPageX),
  188.     OPCODEMODE(AND, AbsoluteX),
  189.     OPCODEMODE(AND, AbsoluteY),
  190.     OPCODEMODE(ASL, Absolute),
  191.     OPCODEMODE(ASL, ZeroPage),
  192.     OPCODEMODE(ASL, Accumulator),
  193.     OPCODEMODE(ASL, ZeroPageX),
  194.     OPCODEMODE(ASL, AbsoluteX),
  195.     OPCODEMODE(BCC, Relative),
  196.     OPCODEMODE(BCS, Relative),
  197.     OPCODEMODE(BEQ, Relative),
  198.     OPCODEMODE(BNE, Relative),
  199.     OPCODEMODE(BMI, Relative),
  200.     OPCODEMODE(BPL, Relative),
  201.     OPCODEMODE(BVC, Relative),
  202.     OPCODEMODE(BVS, Relative),
  203.     OPCODEMODE(BIT, Absolute),
  204.     OPCODEMODE(BIT, ZeroPage),
  205.     OPCODEMODE(BRK, None),
  206.     OPCODEMODE(CLC, None),
  207.     OPCODEMODE(CLD, None),
  208.     OPCODEMODE(CLI, None),
  209.     OPCODEMODE(CLV, None),
  210.     OPCODEMODE(CMP, Immediate),
  211.     OPCODEMODE(CMP, Absolute),
  212.     OPCODEMODE(CMP, ZeroPage),
  213.     OPCODEMODE(CMP, IndX),
  214.     OPCODEMODE(CMP, IndY),
  215.     OPCODEMODE(CMP, ZeroPageX),
  216.     OPCODEMODE(CMP, AbsoluteX),
  217.     OPCODEMODE(CMP, AbsoluteY),
  218.     OPCODEMODE(CPX, Immediate),
  219.     OPCODEMODE(CPX, Absolute),
  220.     OPCODEMODE(CPX, ZeroPage),
  221.     OPCODEMODE(CPY, Immediate),
  222.     OPCODEMODE(CPY, Absolute),
  223.     OPCODEMODE(CPY, ZeroPage),
  224.     OPCODEMODE(DEC, Absolute),
  225.     OPCODEMODE(DEC, ZeroPage),
  226.     OPCODEMODE(DEC, ZeroPageX),
  227.     OPCODEMODE(DEC, AbsoluteX),
  228.     OPCODEMODE(DEX, None),
  229.     OPCODEMODE(DEY, None),
  230.     OPCODEMODE(EOR, Immediate),
  231.     OPCODEMODE(EOR, Absolute),
  232.     OPCODEMODE(EOR, ZeroPage),
  233.     OPCODEMODE(EOR, IndX),
  234.     OPCODEMODE(EOR, IndY),
  235.     OPCODEMODE(EOR, ZeroPageX),
  236.     OPCODEMODE(EOR, AbsoluteX),
  237.     OPCODEMODE(EOR, AbsoluteY),
  238.     OPCODEMODE(INC, Absolute),
  239.     OPCODEMODE(INC, ZeroPage),
  240.     OPCODEMODE(INC, ZeroPageX),
  241.     OPCODEMODE(INC, AbsoluteX),
  242.     OPCODEMODE(INX, None),
  243.     OPCODEMODE(INY, None),
  244.     OPCODEMODE(JMP, Absolute),
  245.     OPCODEMODE(JMP, Indirect),
  246.     OPCODEMODE(JSR, Absolute),
  247.     OPCODEMODE(LDA, Immediate),
  248.     OPCODEMODE(LDA, Absolute),
  249.     OPCODEMODE(LDA, ZeroPage),
  250.     OPCODEMODE(LDA, IndX),
  251.     OPCODEMODE(LDA, IndY),
  252.     OPCODEMODE(LDA, ZeroPageX),
  253.     OPCODEMODE(LDA, AbsoluteX),
  254.     OPCODEMODE(LDA, AbsoluteY),
  255.     OPCODEMODEEXCEPTION(LDX, Immediate, _LDX_Immediate),
  256.     OPCODEMODE(LDX, Absolute),
  257.     OPCODEMODE(LDX, ZeroPage),
  258.     OPCODEMODE(LDX, AbsoluteY),
  259.     OPCODEMODE(LDX, ZeroPageY),
  260.     OPCODEMODEEXCEPTION(LDY, Immediate, _LDY_Immediate),
  261.     OPCODEMODE(LDY, Absolute),
  262.     OPCODEMODE(LDY, ZeroPage),
  263.     OPCODEMODE(LDY, ZeroPageX),
  264.     OPCODEMODE(LDY, AbsoluteX),
  265.     OPCODEMODE(LSR, Absolute),
  266.     OPCODEMODE(LSR, ZeroPage),
  267.     OPCODEMODE(LSR, Accumulator),
  268.     OPCODEMODE(LSR, ZeroPageX),
  269.     OPCODEMODE(LSR, AbsoluteX),
  270.     OPCODEMODE(NOP, None),
  271.     OPCODEMODE(ORA, Immediate),
  272.     OPCODEMODE(ORA, Absolute),
  273.     OPCODEMODE(ORA, ZeroPage),
  274.     OPCODEMODE(ORA, IndX),
  275.     OPCODEMODE(ORA, IndY),
  276.     OPCODEMODE(ORA, ZeroPageX),
  277.     OPCODEMODE(ORA, AbsoluteX),
  278.     OPCODEMODE(ORA, AbsoluteY),
  279.     OPCODEMODE(PHA, None),
  280.     OPCODEMODE(PHP, None),
  281.     OPCODEMODE(PLA, None),
  282.     OPCODEMODE(PLP, None),
  283.     OPCODEMODE(ROL, Absolute),
  284.     OPCODEMODE(ROL, ZeroPage),
  285.     OPCODEMODE(ROL, Accumulator),
  286.     OPCODEMODE(ROL, ZeroPageX),
  287.     OPCODEMODE(ROL, AbsoluteX),
  288.     OPCODEMODE(ROR, Absolute),
  289.     OPCODEMODE(ROR, ZeroPage),
  290.     OPCODEMODE(ROR, Accumulator),
  291.     OPCODEMODE(ROR, ZeroPageX),
  292.     OPCODEMODE(ROR, AbsoluteX),
  293.     OPCODEMODE(RTI, None),
  294.     OPCODEMODE(RTS, None),
  295.     OPCODEMODE(SBC, Immediate),
  296.     OPCODEMODE(SBC, Absolute),
  297.     OPCODEMODE(SBC, ZeroPage),
  298.     OPCODEMODE(SBC, IndX),
  299.     OPCODEMODE(SBC, IndY),
  300.     OPCODEMODE(SBC, ZeroPageX),
  301.     OPCODEMODE(SBC, AbsoluteX),
  302.     OPCODEMODE(SBC, AbsoluteY),
  303.     OPCODEMODE(SEC, None),
  304.     OPCODEMODE(SED, None),
  305.     OPCODEMODE(SEI, None),
  306.     OPCODEMODE(STA, Absolute),
  307.     OPCODEMODE(STA, ZeroPage),
  308.     OPCODEMODE(STA, IndX),
  309.     OPCODEMODE(STA, IndY),
  310.     OPCODEMODE(STA, ZeroPageX),
  311.     OPCODEMODE(STA, AbsoluteX),
  312.     OPCODEMODE(STA, AbsoluteY),
  313.     OPCODEMODE(STX, Absolute),
  314.     OPCODEMODE(STX, ZeroPage),
  315.     OPCODEMODE(STX, ZeroPageY),
  316.     OPCODEMODE(STY, Absolute),
  317.     OPCODEMODE(STY, ZeroPage),
  318.     OPCODEMODE(STY, ZeroPageX),
  319.     OPCODEMODE(TAX, None),
  320.     OPCODEMODE(TAY, None),
  321.     OPCODEMODE(TSX, None),
  322.     OPCODEMODE(TXA, None),
  323.     OPCODEMODE(TXS, None),
  324.     OPCODEMODE(TYA, None)
  325. };
  326.